package com.wdz.utils.m_lang;


import com.wdz.utils.transformation.StringTransformation;

public class StringUtils implements StringTransformation {

    private static StringUtils stringUtils;

    private StringUtils(){

    }

    public static StringUtils getInstance(){
        if(stringUtils == null){
            stringUtils = new StringUtils();
        }
        return stringUtils;
    }

    /**
     * 首字母转换为大写，其余的都转换为小写
     * @param str 需要转换的字符串
     * @return
     */
    @Override
    public String tran1(String str) {
        String xiaoxie = "qwertyuiopasdfghjklzxcvbnm";
        String daxie = "QWERTYUIOPASDFGHJKLZXCVBNM";
        char[] chars = str.toCharArray();
        int i;
        StringBuilder stringBuilder = new StringBuilder();
        for(char cha : chars){
            i = daxie.indexOf(cha);
            if(i != -1){
                stringBuilder.append(xiaoxie.charAt(i));
            }else{
                stringBuilder.append(cha);
            }
        }
        str = stringBuilder.toString();
        str = tran2(0,daxie.charAt(xiaoxie.indexOf(str.charAt(0))),str);
        return str;
    }

    /**
     * 对字符串的某个字符转换成其他的字符
     * @param index 需要转换的字符的下标，以0开始
     * @param v 转换后的字符
     * @param str 需要转换的字符串
     * @return
     */
    @Override
    public String tran2(int index, char v,String str) {
        char[] chars = str.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        int chars_length = chars.length;
        for(int i=0;i<chars_length;i++){
            if(i == index){
                stringBuilder.append(v);
            }else{
                stringBuilder.append(chars[i]);
            }
        }
        return stringBuilder.toString();
    }



    public static void main(String[] args) {
        int type = 0;
        switch (type){
            case 0 | 1:
                System.out.println("pp");
                break;
        }
    }
}
